package com.meixiang.fragment;


import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;

import com.bumptech.glide.Glide;
import com.meixiang.R;
import com.meixiang.entity.ShowPicture;
import com.meixiang.main.BaseFragment;
import com.meixiang.view.TouchImageView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 图片fragment
 */
public class ZoomImageViewFragment extends BaseFragment {
    @Bind(R.id.tiv_content)
    TouchImageView mTivContent;
    @Bind(R.id.progress)
    ProgressBar mProgress;
    private ShowPicture mShowPicture;
    private View view;

    private ImgOnclickListener mListener;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        try {
            mListener = (ImgOnclickListener) context;
        } catch (RuntimeException e) {
            new IllegalThreadStateException("please implement ImgOnclickListener in the Activity");
        }

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_zoom_image_view, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    protected void initTitle() {

    }

    @Override
    protected void initView() {
        Bundle bundle = getArguments();
        mShowPicture = bundle.getParcelable("picture");
        /*if (null != mShowPicture.getBitmap()) {
            mTivContent.setImageBitmap(mShowPicture.getBitmap());
        }*/
        Glide.with(this).load(mShowPicture.getStepImage()).thumbnail(0.1f).into(mTivContent);
        /*setImageUrl(R.mipmap.ic_launcher, mShowPicture.getStepImage(), mTivContent, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {
            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {

            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {

            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });*/

    }

    @Override
    protected void setData() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick(R.id.tiv_content)
    public void onClick(View view) {
        if (view.equals(mTivContent)){
            mListener.ImgOnClick(view);
        }
    }

    public interface ImgOnclickListener {
        void ImgOnClick(View view);
    }
}
